precision mediump float;

uniform sampler2D u_sampler2D;

uniform vec3 u_lightPosition;
uniform vec4 u_lightDiffuse;
uniform vec4 u_lightAmbient;
uniform vec4 u_lightSpecular;
uniform float u_lightShininess;
uniform float u_lightWeight;

varying vec3 v_normalW;
varying vec2 v_uv;
varying vec3 v_toEye;

void main()
{
	vec4 tex = texture2D(u_sampler2D, v_uv);
	vec3 light = -normalize(u_lightPosition);
	vec3 lightReflect = normalize(reflect(light, v_normalW));

	vec4 diffuse = u_lightDiffuse * max(dot(v_normalW, -light), 0.0);
	vec4 ambient = u_lightAmbient;
	vec4 specular = u_lightSpecular * pow(max(dot(lightReflect, -v_toEye), 0.0), u_lightShininess);
	
	gl_FragColor = vec4(((u_lightWeight * ambient + (1.0 - u_lightWeight) * diffuse) * tex + specular).zxy, 1.0);
}
